home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cppmatrx.zip / MATPARSE.BAK < prev    next >
Text File  |  1991-02-02  |  1KB  |  61 lines

  1. #include <math.h>
  2. #include <iostream.h>
  3.  
  4. #include "matrix.h"
  5. #include "matparse.h"
  6.  
  7. static char current_token;
  8.  
  9. matrix expression (void)
  10. {
  11.    matrix left = term ();
  12.  
  13.    while (1)   {
  14.          switch (current_token)   {
  15.                case '+':
  16.                   left = left + term (); break;
  17.  
  18.                case '-':
  19.                   left = left - term (); break;
  20.  
  21.                case '!':
  22.                   return left;
  23.  
  24.                default:
  25.                   matrix_error ("Invalid character in expression.");
  26.             }
  27.       }
  28. }
  29.  
  30.  
  31. matrix term (void)
  32. {
  33.    matrix left = primary ();
  34.  
  35.    switch (get_token ())   {
  36.          case '*':
  37.             left = left*primary (); break;
  38.  
  39.          default:
  40.             return left;
  41.       }
  42. }
  43.  
  44. matrix  primary (void)
  45. {
  46.    char ch;
  47.    matrix temp ("*",2);
  48.  
  49.    cin >> ch;
  50.    cin >> temp;
  51.    cin >> ch;
  52.  
  53.    return temp;
  54. }
  55.  
  56. char get_token (void)
  57. {
  58.    cin >> current_token;
  59.    return current_token;
  60. }
  61.